package com.string;

import java.util.Random;

public class RandomString {
	/*
	 * 随机生成字符串
	 * 设计思路,传入固定字符串，随机获得每个字符的下标。
	 */
	
	public final static String N0_9 = "0123456789";
	public final static String a_z = "abcdefghijklmnopqrstuvwxyz";
	public final static String A_Z = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	public final static String A_Za_z =a_z+A_Z;
	public final static String a_z0_9 = a_z+N0_9;
	public final static String A_Z0_9 = A_Z+N0_9;
	public final static String A_Za_z0_9 = A_Za_z+N0_9;
	
	/**
	 * @param stringLength 字符串长度
	 * @param indexSize	   生成下标数量
	 * @return
	 */
	public static int[] getIndexs(int stringLength,int indexSize){
		Random r = new Random();
		int[] indexs = new int[indexSize];
		for (int i = 0; i < indexs.length; i++) {
			indexs[i] = r.nextInt(stringLength);
		}
		return indexs;
	}
	/**
	 * @param selectString	可选择的字符串,从里面选择内容随机
	 * @param outLength		最终字符串输出长度
	 * @return
	 */
	public static String getRandomString(String selectString,int outLength){
		int[] indexs = getIndexs(selectString.length(), outLength);
		StringBuilder text = new StringBuilder(outLength);
		for (int index : indexs) {
			text.append(selectString.charAt(index));
		}
		return text.toString();
	}
	
	
	public static void main(String[] args) {
		String bb = "abz";
		String abc = "abcabcabdabdabcabfabcabcabdabdabcabfabcabcabdabdabcababbzzfabcabcabdabdabcabfabcabcabdabdabcabfabcabcabdabdabcabf";
		String cc = "abz";
		StringBuilder x = new StringBuilder();
		for (int i = 0; i < 500000; i++) {
			x.append(bb);
		}//abbzz
		x.append(abc);
		for (int i = 0; i < 100; i++) {
			x.append(cc);
		}
		String n = x.toString();
		
		System.out.println(n.indexOf("abbzz"));
		
	}
}
